package zuwotest;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.junit.Test;

import cn.diancan.exception.OutMsgException;
import cn.diancan.model.Brand;
import cn.diancan.model.Goods;
import cn.diancan.model.GoodsCategory;
import cn.diancan.model.Product;
import cn.diancan.model.ProductSpecificationValues;
import cn.diancan.model.Specification;
import cn.diancan.model.SpecificationValue;
import cn.diancan.vo.model.ProductVo;
import cn.diancan.vo.model.SpecificationVo;
import cn.diancan.vo.other.Pager;

public class ProductTest extends BaseTest{
    
    @Test
    public void saveBrand(){
	try {
	   Brand s =    brandService.saveBrand("品牌1","http://www.baidu.com/img/bd_logo1.png");
	   System.out.println(s);
	} catch (OutMsgException e) {
	    e.printStackTrace();
	} catch (Exception e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	}
    }
    
    @Test
    public void saveGoodsCategory(){
	try {
	    GoodsCategory s = goodsCategoryService.saveGoodsCategory(null,"分类1",0 );
	    System.out.println(s);
	} catch (OutMsgException e) { 
	    e.printStackTrace();
	} catch (Exception e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	}
	
    }
    
    @Test
    public void saveSpecification(){
	try {
	    Specification s =specificationService.saveSpecification("颜色", new String[]{"红色","蓝色","白色","蓝色"});
	   s =specificationService.saveSpecification("尺寸", new String[]{"29","31","32","33"});
	    System.out.println(s);
	} catch (Exception e) { 
	    e.printStackTrace();
	}
    }
    
    @Test
    public void saveGoods(){
	try {
	    boolean s = goodsService.saveGoods(141922l, 141922l, "1235", "2016新款", "2016新款","12345123451");
	    System.out.println(s);
	} catch (OutMsgException e) { 
	    e.printStackTrace();
	} catch (Exception e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	}
    }
    
    
    @Test
    public void saveProduct(){
	try {
	   boolean s =    productService.saveProduct(141927l, new Long []{141925l,141924l}, "12345123451", 26d, 26d,99999);
	   System.out.println(s);
	}catch (OutMsgException e) { 
	    e.printStackTrace();
	} catch (Exception e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	}
    }
    
    @Test
    public void f3(){
	try {
	    //12 14 15 16 17 18 19  20 22 25 
	   // 29d,39d,49d,59d,69d,79d,89d,99d,109d,119d,129d,139d,149d,159d,169d,179d,189d,199d,209d,219d,229d,239d,249d,259d,269d,279d,289d,299d,309d 
	    //Double[] prices = new Double[]{ 10d };
	    
	    /*List<Double> prices= new ArrayList<Double>();
	    for (int i = 10; i <= 400; i++) {
		prices.add(Double.valueOf(""+i));
	    }*/
	    List<Double> prices= new ArrayList<Double>();
	    for (int i = 1; i <= 10; i++) {
		prices.add(Double.valueOf(""+i));
	    }
	    
	    
	    for(int i = 0 ;i<prices.size();i++){
	           try {
	               Double price= prices.get(i);
		       String goodsNumber ="X00"+price.intValue();
		       Goods goods =new Goods(); 
		       goods.setBrandId(141922l);
		       goods.setGoodsCategoryId(142631l);
		       goods.setGoodsNumber(goodsNumber);
		       goods.setGoodsName(goodsNumber);
		       goods.setRangeStr("");
		       goods.setRetailPrice(price);
		       //标签价格和售价
		       goods.setTagPrice(price);
		       goods.setUnit("件");
		       
		       Calendar a=Calendar.getInstance();
		       //得到当前年份
		       goods.setYear(""+a.get(Calendar.YEAR));//得到年
		       goods.setSeason("全部");
		       goods.setApplySex(2);
		       goods.setGoodsRemark("系统内置");
		       goods=  goodsService.saveGoods(goods,false );
		       
		       
		       Boolean result = productService.saveColorAndSizeProductList(goods.getId(), new Long[]{143781l}, new Long []{142842l});
		} catch (Exception e) {
		    // TODO Auto-generated catch block
		    e.printStackTrace();
		}
	    }
	} catch (Exception e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	} 
	
    }
    @Test
    public void t4(){
	 try {
	    Boolean result = productService.saveColorAndSizeProductList(151179l, new Long[]{143781l}, new Long []{142842l});
	} catch (OutMsgException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	} catch (Exception e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	}
    }
    
    
    @Test
    public void findProduct(){
	try {
	    Product product =productService.findByProductBarcode("61116203402");
	    List<ProductSpecificationValues> sroductSpecificationValuesList =product.getSroductSpecificationValuesList();
	    for (int i = 0; i < sroductSpecificationValuesList.size(); i++) {
	        ProductSpecificationValues values=  sroductSpecificationValuesList.get(i);
	        
	        SpecificationValue spValue =  values.getSpecificationValue();
	        Specification sp =  spValue.getSpecification();
	        System.out.println(sp.getName() +" "+spValue.getValue());
	    }
	} catch (Exception e) { 
	    e.printStackTrace();
	}
    }
    
    @Test
    public void f(){
	List<SpecificationVo> list =productService.findColorSpecificationValueByGoodsNumber("03286202");
	List<SpecificationVo> list2 =productService.findSizeSpecificationValueByGoodsNumber("03286202");
	System.out.println(list);
	System.out.println(list2);
    }
    
    @Test
    public void f2(){
	try {
	   
	   List<ProductVo> list=  purchaseSaleOrderBuyCarService.findProductVoBySysManagerId(10000l);
	   System.out.println(list);
	   Pager pager =new Pager();
	   
	   purchaseSaleOrderBuyCarService.findByPager(10000l, pager);
	   
	} catch (OutMsgException e) {
	    e.printStackTrace();
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
  
   
    

}
